/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package uimigration.UIModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import uimigration.Interactions.Behaviour;
import uimigration.UIModel.Event;
import uimigration.UIModel.Property;
import uimigration.UIModel.UIModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link uimigration.UIModel.impl.EventImpl#getName <em>Name</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.EventImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.EventImpl#getScriptCode <em>Script Code</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.EventImpl#getImplementedEventBehaviour <em>Implemented Event Behaviour</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.EventImpl#getLinkedProperty <em>Linked Property</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EventImpl extends EObjectImpl implements Event {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getParameters() <em>Parameters</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameters()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<String> parameters;

	/**
	 * The default value of the '{@link #getScriptCode() <em>Script Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScriptCode()
	 * @generated
	 * @ordered
	 */
	protected static final String SCRIPT_CODE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getScriptCode() <em>Script Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScriptCode()
	 * @generated
	 * @ordered
	 */
	protected String scriptCode = SCRIPT_CODE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getImplementedEventBehaviour() <em>Implemented Event Behaviour</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getImplementedEventBehaviour()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Behaviour> implementedEventBehaviour;

	/**
	 * The cached value of the '{@link #getLinkedProperty() <em>Linked Property</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinkedProperty()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Property> linkedProperty;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return UIModelPackage.Literals.EVENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UIModelPackage.EVENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<String> getParameters() {
		if (parameters == null) {
			parameters = new EDataTypeUniqueEList<String>(String.class, this,
					UIModelPackage.EVENT__PARAMETERS);
		}
		return parameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getScriptCode() {
		return scriptCode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setScriptCode(String newScriptCode) {
		String oldScriptCode = scriptCode;
		scriptCode = newScriptCode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UIModelPackage.EVENT__SCRIPT_CODE, oldScriptCode, scriptCode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Behaviour> getImplementedEventBehaviour() {
		if (implementedEventBehaviour == null) {
			implementedEventBehaviour = new EObjectContainmentEList<Behaviour>(
					Behaviour.class, this,
					UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR);
		}
		return implementedEventBehaviour;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Property> getLinkedProperty() {
		if (linkedProperty == null) {
			linkedProperty = new EObjectContainmentEList<Property>(
					Property.class, this, UIModelPackage.EVENT__LINKED_PROPERTY);
		}
		return linkedProperty;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR:
			return ((InternalEList<?>) getImplementedEventBehaviour())
					.basicRemove(otherEnd, msgs);
		case UIModelPackage.EVENT__LINKED_PROPERTY:
			return ((InternalEList<?>) getLinkedProperty()).basicRemove(
					otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case UIModelPackage.EVENT__NAME:
				return getName();
			case UIModelPackage.EVENT__PARAMETERS:
				return getParameters();
			case UIModelPackage.EVENT__SCRIPT_CODE:
				return getScriptCode();
			case UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR:
				return getImplementedEventBehaviour();
			case UIModelPackage.EVENT__LINKED_PROPERTY:
				return getLinkedProperty();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	@SuppressWarnings("unchecked")
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case UIModelPackage.EVENT__NAME:
			setName((String) newValue);
			return;
		case UIModelPackage.EVENT__PARAMETERS:
			getParameters().clear();
			getParameters().addAll((Collection<String>) newValue);
			return;
		case UIModelPackage.EVENT__SCRIPT_CODE:
			setScriptCode((String) newValue);
			return;
		case UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR:
			getImplementedEventBehaviour().clear();
			getImplementedEventBehaviour().addAll((Collection<? extends Behaviour>) newValue);
			return;
		case UIModelPackage.EVENT__LINKED_PROPERTY:
			getLinkedProperty().clear();
			getLinkedProperty().addAll((Collection<? extends Property>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case UIModelPackage.EVENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case UIModelPackage.EVENT__PARAMETERS:
				getParameters().clear();
				return;
			case UIModelPackage.EVENT__SCRIPT_CODE:
				setScriptCode(SCRIPT_CODE_EDEFAULT);
				return;
			case UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR:
				getImplementedEventBehaviour().clear();
				return;
			case UIModelPackage.EVENT__LINKED_PROPERTY:
				getLinkedProperty().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case UIModelPackage.EVENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case UIModelPackage.EVENT__PARAMETERS:
				return parameters != null && !parameters.isEmpty();
			case UIModelPackage.EVENT__SCRIPT_CODE:
				return SCRIPT_CODE_EDEFAULT == null ? scriptCode != null : !SCRIPT_CODE_EDEFAULT.equals(scriptCode);
			case UIModelPackage.EVENT__IMPLEMENTED_EVENT_BEHAVIOUR:
				return implementedEventBehaviour != null && !implementedEventBehaviour.isEmpty();
			case UIModelPackage.EVENT__LINKED_PROPERTY:
				return linkedProperty != null && !linkedProperty.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	public boolean containsBehavior(Behaviour b)
	{
		if(implementedEventBehaviour!=null)
			for(Behaviour bi : implementedEventBehaviour)
			{
				if(bi.eClass().getName().compareTo(b.eClass().getName())==0)
					return true;
			}
		return false;
	}
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", parameters: ");
		result.append(parameters);
		result.append(", scriptCode: ");
		result.append(scriptCode);
		result.append(')');
		return result.toString();
	}

} //EventImpl
